<template>
	<view class="page" :style="{'min-height':h+'px'}">
		<!-- 头部 -->
		<u-navbar title="在线预约" :autoBack="true" :leftIconSize="36" bgColor="#ffffff" leftIconColor="#111111" :titleStyle="titleStyle"></u-navbar>
		<view class="content" :style="{'margin-top':mt+'px'}">
			<view class="c_booking">
				<view class="cb_fw">
					<text>预约服务</text>
					<text>{{object.title}}</text>
				</view>
				<view class="cb_qm">
					<view class="cbq_l">
						<text>预约券码张数</text>
						<text>商家核销后，券码才会失效</text>
					</view>
					<view class="cbq_r">
						<image src="@/static/index/steamerTicket/img_reduce.jpg" @tap="reduceNum"></image>
						<text>{{num}}</text>
						<image src="@/static/index/steamerTicket/img_increase.jpg" @tap="increaseNum"></image>
					</view>
				</view>
				<view class="cb_info">
					<view class="cbi_title">
						<text>预约人信息</text>
						<text>选择常用联系人</text>
					</view>
					<view class="cbi_item">
						<text>联系人</text>
						<input type="text" placeholder="请填写联系人信息" v-model="contactName" @blur="setContactName" @confirm="setContactName">
					</view>
					<view class="cbi_item">
						<text>手机号</text>
						<input type="phone" placeholder="请填写手机号" v-model="contactPhone" @blur="setContactPhone" @confirm="setContactPhone">
					</view>
				</view>
			</view>
			<view class="c_merchant">
				<view class="cm_title">
					<text>商家信息</text>
					<view class="cmt_r" @tap="infoShow=true">
						<text>{{object.merchant}}</text>
						<image src="@/static/index/steamerTicket/icon_yjt.png"></image>
					</view>
				</view>
				<view class="cm_time">
					<text class="cmt_title">游玩时间</text>
					<view class="cmt_date">
						<u-scroll-list :indicator="false">
							<view class="cd_item" v-for="(item,index) in dateList" :key="index" :class="didx===index?'active':''" @tap="changeDate(item,index)">
								<text>{{item.week}}</text>
								<text>{{item.dateYr}}</text>
							</view>
						</u-scroll-list>
					</view>
					<view class="cmt_time">
						<view v-for="(item,index) in timeList" :key="index" :class="tidx===index?'active':(!item.keyue?'yueman':'')" @tap="changeTime(item,index)">
							<text>{{item.time}}</text>
							<text>{{item.keyue?'可约':'约满'}}</text>
							<image v-if="tidx===index" src="https://i.ringzle.com/file/20231111/980540baf19b47ae9c0c4b258e3803cb.png"></image>
						</view>
					</view>
				</view>
				<view class="cm_upload">
					<view class="cmu_title">
						<text>上传海钓许可证</text>
						<text>（海钓许可证请与游客信息保持一致）</text>
					</view>
					<view class="cmu_sczj">
						<u-upload
							:fileList="fileList"
							@afterRead="afterRead"
							@delete="deletePic"
							multiple
							:maxCount="2"
							width="100%"
							height="180"
						>
							<view class="cs_sc">
								<image src="https://i.ringzle.com/file/20231111/1f96a220e7104c22a406d7bc4f80b9ff.png"
								mode="widthFix" style="width: 48rpx;height: 48rpx;"></image>
								<text>上传证件</text>
							</view>
							
						</u-upload>
					</view>
				</view>
				<view class="cm_memo">
					<text>备注</text>
					<input type="text" placeholder="选填，可输入您的其他需求" v-model="memo" @blur="setMemo" @confirm="setMemo">
				</view>
			</view>
			<view class="c_btn">
				<view class="cb_btn" @tap="toBooking">立即预约</view>
			</view>
		</view>
		<u-popup :show="infoShow" @close="infoShow=false">
			<view class="details">
				<view class="title">
					<text>商家信息</text>
					<image src="@/static/index/steamerTicket/icon_close.png" @tap="infoShow=false"></image>
				</view>
				<view class="d_content">
					<text>{{merchantInfo.title}}</text>
					<text>{{merchantInfo.address}}</text>
					<text>资质</text>
					<image :src="merchantInfo.img"></image>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				h: uni.getWindowInfo().windowHeight,
				mt: uni.getSystemInfoSync().statusBarHeight + 44,
				titleStyle: {
					fontSize: '36rpx',
					fontWeight: "bold",
					color: "#111111"
				},
				object:null,
				num:1,
				week:['周日','周一','周二','周三','周四','周五','周六'],
				didx:0,
				dateList:[],
				date:'',
				tidx:'',
				timeList:[],
				time:'',
				contactName:uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).realName:'',
				contactPhone:uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).mobile:'',
				memo:'',
				fileList:[],
				infoShow:false,
				merchantInfo:{
					title:'北海朝阳海钓基地',
					address:'舟山市嵊泗县五龙乡沿港路51号',
					img:'https://i.ringzle.com/file/20231110/4be0caca8a15466293b9e63d51a188c8.png'
				}
			}
		},
		onLoad(option) {
			if(option.object){
				this.object = JSON.parse(option.object);
			}
			this.dateInit();
			this.timeInit();
		},
		methods: {
			dateInit(){
				this.dateList = [];
				for(let i=0;i<31;i++){
					this.dateList.push({
						date:new Date(new Date().setDate(new Date().getDate()+i)).Format('yyyy-MM-dd hh:mm:ss'),
						week:i===0?'今天':(this.week[new Date(new Date().setDate(new Date().getDate()+i)).getDay()]),
						dateYr:new Date(new Date().setDate(new Date().getDate()+i)).Format('MM-dd')
					})
				}
				this.date = this.dateList[0].date;
			},
			timeInit(){
				this.timeList = [];
				for(let i=0;i<8;i++){
					this.timeList.push({
						time:(10+i)+':00',
						keyue:(i==3||i==4)?true:false
					})
				}
				this.time = this.timeList[0].time;
			},
			changeDate(item,index){
				this.date = item.date;
				this.didx = index;
				this.tidx = '';
				this.time = '';
			},
			changeTime(item,index){
				if(!item.keyue) return
				this.time = item.time;
				this.tidx = index;
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			toBooking(){
				if(!this.$reg.mobile(this.contactPhone)) return this.$showToast('请输入正确的手机号');
				uni.navigateTo({
					url:'/pagesMy/seaFishingOrder/bookingResult?latitude=30.707706&longitude=122.512712'
				})
			}
		}
	}
</script>

<style scoped lang="less">
	/deep/.u-upload,/deep/.u-upload__wrap,/deep/.u-upload__wrap>view{
		width: 100%;
		height: 100%;
	}
	/deep/.u-popup__content,/deep/.u-popup__content .details{
		border-radius: 24rpx 24rpx 0rpx 0rpx !important;
	}
	
	.page{
		.content{
			.c_booking{
				width: 100%;
				padding: 0 24rpx;
				box-sizing: border-box;
				&>view{
					display: flex;
					justify-content: space-between;
				}
				.cb_fw{
					align-items: center;
					padding: 28rpx 0;
					text{
						font-size: 30rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						&:first-child{
							color: #777777;
						}
						&:last-child{
							color: #111111;
						}
					}
				}
				.cb_qm{
					padding: 29rpx 0 37rpx;
					border-top: 1rpx solid rgba(112, 112, 112, .1);
					.cbq_l{
						display: flex;
						flex-direction: column;
						text{
							font-size: 30rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #777777;
							&:last-child{
								font-size: 24rpx;
								color: #999999;
								margin-top: 18rpx;
							}
						}
					}
					.cbq_r{
						display: flex;
						align-items: center;
						image{
							width: 44rpx;
							height: 44rpx;
						}
						text{
							font-size: 28rpx;
							font-family: PingFang-SC-Bold, PingFang-SC;
							font-weight: bold;
							color: #333333;
							padding: 0 30rpx;
						}
					}
				}
				.cb_info{
					flex-direction: column;
					justify-content: inherit;
					padding-top: 39rpx;
					border-top: 1rpx solid rgba(112, 112, 112, .1);
					&>view{
						display: flex;
						align-items: center;
						justify-content: space-between;
					}
					.cbi_title{
						padding-bottom: 9rpx;
						text{
							font-size: 32rpx;
							font-family: PingFang-SC-Bold, PingFang-SC;
							font-weight: bold;
							color: #333333;
							&:last-child{
								font-size: 24rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #FF7D01;
							}
						}
					}
					.cbi_item{
						padding: 28rpx 0;
						&:last-child{
							border-top: 1rpx solid rgba(112, 112, 112, .1);
						}
						text{
							font-size: 26rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #777777;
						}
						input{
							border: none;
							outline: none;
							text-align: right;
							font-size: 26rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #777777;
							&::placeholder{
								color: #AAAAAA;
							}
						}
					}
				}
			}
			
			.c_merchant{
				width: 100%;
				padding: 0 24rpx;
				box-sizing: border-box;
				border-top: 20rpx solid #F5F8FA;
				.cm_title{
					padding: 28rpx 0;
					display: flex;
					align-items: center;
					justify-content: space-between;
					&>text{
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #777777;
					}
					.cmt_r{
						display: flex;
						align-items: center;
						text{
							font-size: 26rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #333333;
						}
						image{
							width: 24rpx;
							height: 24rpx;
							margin-left: 10rpx;
						}
					}
				}
				.cm_time{
					padding-top: 40rpx;
					border-top: 1rpx solid rgba(112, 112, 112, .1);
					.cmt_title{
						font-size: 32rpx;
						font-family: PingFang-SC-Bold, PingFang-SC;
						font-weight: bold;
						color: #333333;
					}
					.cmt_date{
						display: flex;
						align-items: center;
						width: 100%;
						overflow-x: auto;
						padding-top: 40rpx;
						.cd_item{
							width: 146rpx;
							position: relative;
							padding-bottom: 30rpx;
							display: flex;
							flex-direction: column;
							align-items: center;
							&:first-child{
								margin-left: -20rpx;
							}
							text{
								font-size: 30rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #666666;
								&:last-child{
									font-size: 24rpx;
									color: #646464;
									margin-top: 4rpx;
								}
							}
							&.active{
								text{
									&:first-child{
										font-size: 30rpx;
										font-family: PingFang-SC-Bold, PingFang-SC;
										font-weight: bold;
										color: #333333;
									}
								}
								&::after{
									content: '';
									width: 64rpx;
									height: 6rpx;
									background: #01B9F9;
									border-radius: 5rpx;
									position: absolute;
									left: 50%;
									margin-left: -32rpx;
									bottom:2rpx;
								}
							}
						}
					}
					.cmt_time{
						padding: 9rpx 26rpx 0;
						display: flex;
						flex-wrap: wrap;
						justify-content: space-around;
						border-top:1rpx solid rgba(112, 112, 112, .1);
						&>view{
							width: calc(25% - 17rpx);
							height: 110rpx;
							border-radius: 10rpx;
							border: 1rpx solid #E1E1E1;
							margin-top: 20rpx;
							display: flex;
							flex-direction: column;
							align-items: center;
							justify-content: center;
							position: relative;
							text{
								font-size: 26rpx;
								font-family: PingFang-SC-Bold, PingFang-SC;
								font-weight: bold;
								color: #333333;
								&:last-child{
									font-size: 20rpx;
									font-family: PingFangSC-Regular, PingFang SC;
									font-weight: 400;
									margin-top: 7rpx;
								}
							}
							&.yueman{
								text{
									color: #AAAAAA;
								}
							}
							&.active{
								background: #F3FCFF;
								border: 1rpx solid #007A69;
								text{
									color: #007A69 !important;
								}
							}
							
							image{
								width: 34rpx;
								height: 26rpx;
								position: absolute;
								right: 0;
								bottom: 0;
							}
						}
					}
				}
				.cm_upload{
					margin-top: 48rpx;
					.cmu_title{
						display: flex;
						align-items: center;
						text{
							font-size: 32rpx;
							font-family: PingFang-SC-Bold, PingFang-SC;
							font-weight: bold;
							color: #111111;
							&:last-child{
								font-size: 24rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #999999;
								margin-left: 6rpx;
							}
						}
					}
					.cmu_sczj{
						margin-top: 40rpx;
						width: 100%;
						height: 180rpx;
						border-radius: 16rpx;
						border: 1rpx dotted #01B9F9;
						.cs_sc{
							width: 100%;
							height: 100%;
							display: flex;
							align-items: center;
							flex-direction: column;
							justify-content: center;
							text{
								font-size: 24rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #01B9F9;
								margin-top: 20rpx;
							}
						}
					}
				}
				.cm_memo{
					margin-top: 63rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					text{
						font-size: 32rpx;
						font-family: PingFang-SC-Bold, PingFang-SC;
						font-weight: bold;
						color: #333333;
					}
					input{
						width: calc(100% - 80rpx);
						border: none;
						outline: none;
						text-align: right;
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #33333;
						&::placeholder{
							color: #AAAAAA;
						}
					}
				}
			}
		
			.c_btn{
				margin-top: 26rpx;
				border-top: 1rpx solid rgba(112, 112, 112, .1);
				width: 100%;
				padding: 67rpx 24rpx 34rpx;
				box-sizing: border-box;
				.cb_btn{
					width: 100%;
					height: 88rpx;
					background: #007A69;
					border-radius: 44rpx;
					line-height: 88rpx;
					text-align: center;
					font-size: 32rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: #FFFFFF;
					letter-spacing: 2rpx;
				}
			}
		}
		
		.details {
			padding: 40rpx 30rpx 200rpx;
			.title{
				position: relative;
				text-align: center;
		
				text {
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
				}
		
				image {
					width: 36rpx;
					height: 36rpx;
					position: absolute;
					right: 10rpx;
					top: 50%;
					margin-top: -18rpx;
				}
			}
			.d_content{
				margin-top: 33rpx;
				display: flex;
				flex-direction: column;
				text{
					margin-top: 36rpx;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
				}
				image{
					margin-top: 20rpx;
					width: 100%;
					height: 474rpx;
				}
			}
		}
	}
</style>